
package xyy.d3erpapi.task;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import xyy.d3erpapi.service.PopService;

import javax.annotation.PostConstruct;
import java.text.SimpleDateFormat;
import java.util.Date;

@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
@Slf4j
public class SaticScheduleTask {
    @Autowired
    private PopService popService;
    //3.添加定时任务

/***
 * 库存、物流、出库都由点三推送，不做定时任务调用
 */
    /**
     * 订单同步
     */

    @Scheduled(cron = "0 0/1 * * * ? ")
    public void orderPull() {
        long begin = System.currentTimeMillis();
        popService.syncOrderToMerchant();
        long end = System.currentTimeMillis();
        long ms = end - begin;

        log.info("订单同步任务执行时间:{} 本次执行耗时: {} 毫秒", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), ms);
    }



/**
        *心跳检测*/


    @Scheduled(cron = "0 0/2 * * * ? ")
    @PostConstruct

    public void heartbeatDetection() {
        popService.syncHeartBeatMonitor();
        log.info("心跳检测任务执行时间:{} ", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }
}
